import TileLayer from "ol/layer/Tile";
import { XYZ } from "ol/source";

export const createTileLayer = (title, url, options = {}) => {
  const defaults = {
    title,
    projection: 'EPSG:4326',
    tileSize: 256,
  };

  const config = { ...defaults, ...options };

  return new TileLayer({
    properties: { title: config.title },
    source: new XYZ({
      url,
      projection: config.projection,
      tileSize: config.tileSize,
      crossOrigin: 'anonymous'
    }),
    zIndex: config.zIndex || 0
  });
};
